# 阶段性复习，按照步骤完成相应网站的图片数据采集
# ------------测试1---------------------
# 待爬取的网站：http://www.sucaijishi.com/icon/
# 1、导入包
# 2、向网站服务器发起请求，并打印出状态码
# 3、解析网页的图片数据并打印图片的链接
# 4、获取图片并适当命名

import requests
from lxml import etree
url = 'http://www.sucaijishi.com/icon/'
response = requests.get(url)
# response.encoding = response.apparent_encoding
# print(response.status_code)
# html = response.text
ehtml = etree.HTML(response.text)
xtitle = ehtml.xpath("//div[@class='w1180px common_list pt150']/ul/li/a/img//@src")
print(xtitle)
for i in xtitle:
    respic = requests.get(i)
    pic = i[47:]
    with open(pic,'wb') as f:
        f.write(respic.content)